//
//  ZYMainViewController.swift
//  WBBeta1
//
//  Created by wustzhy on 16/8/9.
//  Copyright © 2016年 Yestin. All rights reserved.
//

import UIKit

class ZYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = ZYTabBar()
        //设置代理者
        tabBar.btnDelegate = self
        
//        self.tabBar = ZYTabBar()//只读  
        // KVC 给只读属性 赋值
        self.setValue(tabBar, forKey: "tabBar")
        
        self.addChildViewController(ZYHomeViewController(), title: "主页", imageName: "tabbar_home")
        self.addChildViewController(ZYMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        self.addChildViewController(ZYDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        self.addChildViewController(ZYProfileViewController(), title: "我", imageName: "tabbar_profile")
    }
    
// MARK: - 给tabbarVC添加ChildView
    func addChildViewController(VC:UIViewController,title:String,imageName:String){

//        let HomeVC = ZYHomeViewController()
        //添加 view
        self.addChildViewController(UINavigationController(rootViewController: VC))
        //title设置
//        HomeVC.navigationItem.title = "首页"//01way
//        HomeVC.tabBarItem.title = "首页"
        VC.title = title//02way
        //文字属性设置
        VC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //image设置
        VC.tabBarItem.image = UIImage(named: imageName)
        //Selected image 拼接
//        VC.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")//01way
//        VC.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")//02way
        //图片 渲染
          VC.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //tint color设置
//        self.tabBar.tintColor = UIColor.orangeColor()
        
    }

    
}

extension ZYMainViewController: ZYTabBarDelegate{
    func tabBarButtonClick(){
//        print("点击 撰写按钮")
        //跳转至 compose界面
        let composeVc = ZYComposeViewController()
        self.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
        
        
    }
}



